home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Pascal / Book Demos in Pascal / SpriteEngine / SpriteHandlers.p < prev    next >
Encoding:
Text File  |  1995-04-04  |  1.8 KB  |  71 lines  |  [TEXT/MWPS]

  1. unit SpriteHandlers;
  2.  
  3. interface
  4.  
  5.     uses
  6. {$IFC UNDEFINED THINK_PASCAL}
  7.         Types, QuickDraw, Fonts, Events, Packages, Menus, Dialogs, Windows,{}
  8.         OSUtils, ToolUtils, OSEvents, 
  9. {$ENDC}
  10.         QDOffScreen, SpriteStructure, SpriteTools;
  11.  
  12.     procedure MoveSprite (theSprite: SpritePtr);
  13.     procedure HitSprite (theSprite: SpritePtr; anotherSprite: SpritePtr);
  14.     procedure InitSprites;
  15.  
  16. implementation
  17.  
  18.  
  19. (*** Custom handlers - application dependent ***)
  20.  
  21. {Edit this as necessary. It should always include the following three routines:}
  22.  
  23. {MoveSprite: move the sprite}
  24.  
  25. {HitSprite: handle collisions between two sprites}
  26.  
  27. {InitSprites: Load all faces and create initial sprites}
  28.  
  29.     var
  30.         firstFace, secondFace, thirdFace: GrafPtr;
  31.  
  32.     procedure MoveSprite (theSprite: SpritePtr);
  33.     begin
  34.         theSprite^.position.h := theSprite^.position.h + theSprite^.speed.h;
  35.         theSprite^.position.v := theSprite^.position.v + theSprite^.speed.v;
  36.         if KeepOnScreen(theSprite) then
  37.             ;
  38.     end; (*MoveSprite*)
  39.  
  40.  
  41.     procedure HitSprite (theSprite: SpritePtr; anotherSprite: SpritePtr);
  42.     begin
  43.     end; (*HitSprite*)
  44.  
  45.     procedure InitSprites;
  46.         var
  47.             theSprite: SpritePtr;
  48.     begin
  49. (*Load all pictures*)
  50.         firstFace := LoadFaceFromCicn(128);            (*cicn resource #128.*)
  51.         secondFace := LoadFaceFromCicn(129);            (*cicn resource #129.*)
  52.         thirdFace := LoadFaceFromCicn(130);            (*cicn resource #130.*)
  53.  
  54. (*Create sprites*)
  55.         theSprite := NewSprite;
  56.         theSprite^.face := firstFace;
  57.         SetPt(theSprite^.position, 100, 100);
  58.         SetPt(theSprite^.speed, Rand(7) - 3, Rand(7) - 3);
  59.  
  60.         theSprite := NewSprite;
  61.         theSprite^.face := secondFace;
  62.         SetPt(theSprite^.position, 50, 50);
  63.         SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
  64.  
  65.         theSprite := NewSprite;
  66.         theSprite^.face := thirdFace;
  67.         SetPt(theSprite^.position, 150, 150);
  68.         SetPt(theSprite^.speed, Rand(7)-3, Rand(7)-3);
  69.     end; (*InitSprites*)
  70.  
  71. end.